﻿
-- --------------------------------------------------------------------------------------------------------
-- CREATE [Application] generated on 12/02/2012 07:42:23 by crud.works.tt
-- --------------------------------------------------------------------------------------------------------
IF EXISTS (
  SELECT * FROM INFORMATION_SCHEMA.ROUTINES 
   WHERE SPECIFIC_SCHEMA = N'dbo' AND SPECIFIC_NAME = N'Application_C' 
)
   DROP PROCEDURE dbo.Application_C
GO
CREATE PROCEDURE  dbo.Application_C
	@ApplicationId Int
	,@ApplicationName Char(25)
	,@ApplicationType Char(02)
AS   
BEGIN
	INSERT INTO dbo.Application WITH (ROWLOCK) ( ApplicationId,ApplicationName,ApplicationType )
	VALUES ( @ApplicationId,@ApplicationName,@ApplicationType )
	
	return @@rowcount;
END	
GO


-- --------------------------------------------------------------------------------------------------------
-- UPDATE [Application] generated on 12/02/2012 07:42:23 by crud.works.tt
-- --------------------------------------------------------------------------------------------------------
IF EXISTS (
  SELECT * FROM INFORMATION_SCHEMA.ROUTINES 
   WHERE SPECIFIC_SCHEMA = N'dbo' AND SPECIFIC_NAME = N'Application_U' 
)
   DROP PROCEDURE dbo.Application_U
GO
CREATE PROCEDURE  dbo.Application_U
	@ApplicationId Int
	,@ApplicationName Char(25)
	,@ApplicationType Char(02)
	,@ApplicationVersion timestamp 
AS   
BEGIN
	-- table variable to hold results
	DECLARE @UpdateHold TABLE ( NewRowVersion varbinary );
	
	UPDATE dbo.Application
	SET ApplicationUpdated = GETDATE() 
	OUTPUT inserted.ApplicationVersion into @UpdateHold
	WHERE 
	@ApplicationId = ApplicationId
	-- concurrency check
	AND ApplicationVersion = @ApplicationVersion;
	
	return @@rowcount;
END	
GO

-- --------------------------------------------------------------------------------------------------------
-- DELETE [Application] generated on 12/02/2012 07:42:23 by crud.works.tt
-- --------------------------------------------------------------------------------------------------------
IF EXISTS (
  SELECT * FROM INFORMATION_SCHEMA.ROUTINES 
   WHERE SPECIFIC_SCHEMA = N'dbo' AND SPECIFIC_NAME = N'Application_D' 
)
   DROP PROCEDURE dbo.Application_D
GO
CREATE PROCEDURE  dbo.Application_D
	@ApplicationId Int
	,@ApplicationVersion timestamp
AS   
BEGIN
	DELETE FROM dbo.Application
	WHERE 
	@ApplicationId = ApplicationId
	-- concurrency check
	AND ApplicationVersion = @ApplicationVersion;
	
	return @@rowcount;
END
GO

